package com.xcm.util;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Transformer;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * 集合帮助类
 *
 * @author 林强
 * @date 2018-04-12 11:15
 */
public class CollectionsUtil {

    /**
     * string集合转integer集合
     *
     * @param strList string集合
     * @return
     */
    public static List<Integer> listStrngToInteger(List<String> strList) {
        //去除空元素
        strList.removeAll(Collections.singleton(null));
        strList.removeAll(Collections.singleton(""));
        List<Integer> intList = new ArrayList<>();
        CollectionUtils.collect(strList, new Transformer() {
            @Override
            public Object transform(Object arg0) {
                return Integer.parseInt(arg0.toString().trim());
            }
        }, intList);
        return intList;
    }

    public static void main(String[] args) {
        List<String> strList = Arrays.asList("1,2,3,,   ".trim().replaceAll(" ", "").split(","));
        List<Integer> integers = listStrngToInteger(strList);
        System.out.println(integers);
    }
}
